package org.project.service.mq1;

import java.io.UnsupportedEncodingException;
import javax.annotation.Resource;
import javax.jms.BytesMessage;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

@Component("ibmMessageSender")
public class MessageSenderImpl implements MessageSender {

    @Resource(name="ibmJmsTemplate")
    private JmsTemplate jmsTemplate;

    /**
     * 这里为什么要用final呢？是下面那个createTextMessage方法要求的...
     */
    public void sendMessage(final String message) {
        this.jmsTemplate.send(new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                    return session.createTextMessage(message);
            }
        });
    }

}
